<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
	</head>
		<body>
			
			<!--右边侧栏开始-->
			<div class="right-sidebar" style="max-width: 1200px;">
				<if condition='$role gt 90'>
					<ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
						<li role="presentation" class="active"><a href="pay.html">充值{:L(GAME_RESOURCE)}</a></li>
						<li role="presentation"><a href="payList.html">充值记录</a></li>
						<li role="presentation"><a href="paySearch.html">充值搜索</a></li>
					</ul>
				</if>
				
				<div>
					<if condition="$role lt 99">
					<div class="alert alert-info" style="margin-top: 5px;">剩余{:L(GAME_RESOURCE)}数量：<span class="limit">{$card}</span></div>
					</if>
					<div class="input-group col-md-12">
					  <input type="number" min="0" class="form-control" placeholder="请输入游戏ID" name="user_id" id="user_id">
					  <span class="input-group-addon" id="cbtn">查询</span>
					</div>
					<div class="input-group col-md-12" style="margin-top: 5px;">
					  <input type="number" min="0" class="form-control" placeholder="请输入充值金额" name="number" id="number">
					  <span class="input-group-addon" id="pbtn">充值</span>
					</div>
					
				</div>
				
				<div style="margin-top: 5px;">
					<div class="table-responsive">
						<table class="table table-bordered">
							<thead>
								<tr>
									<th>游戏UID</th>
									<th>微信昵称</th>
									<th>剩余{:L(GAME_RESOURCE)}</th>
									<th>剩余金币</th>
									<th>创建时间</th>
								</tr>
							</thead>
							<tbody id="dataList"></tbody>
						</table>
					</div>
				</div>
				
			</div>
			<script>
				var uname = '';
			    $(document).ready(function () {
			        $('#user_id').blur(function () {
			            var user_id = $.trim($('#user_id').val());
			            if (user_id != '') {
			                var url1 = "{:U('Admin/Login/checkedUidState')}?user_id=" + user_id;
			                $.ajax({
			                    type: "get",
			                    url: url1,
			                    success: function (data) {
			                        if (data == 'unexist') {
			                        	alert("此UID无效！");
			                        	window.location.href="{:U('Admin/Main/pay')}";
			                            return false;
			                        }else{
			                            $.ajax({
                                            type:"get",
                                            url:"{:U('Admin/Main/userDetailInfo')}?user_id=" + user_id,
                                            success:function (res) {
                                                console.log(res);
												if(res != 'nodata') {
                                                    uname = res.info.name;
												}else{
												    alert("未找到该玩家的信息");
												}
                                            }
										})
									}
			                    }
			                });
			            } else {
			            	alert("UID不能为空！");
			            }
			        });
			        
			    $("#cbtn").on("click",function(){
			    	var user_id = $.trim($('#user_id').val());
			    	$.ajax({
			    		type:"post",
			    		url:"{:U('Admin/Main/userDetailInfo')}",
						dataType:"json",
						data:{"user_id":user_id},
			    		success:function(data){
//			    		    console.log(data);
			    			if(!data.status.coin) {
				 				data.status.coin = 0;
				 			}

			    			var str = '';
			    			if(data != 'nodata') {
			    				var time = getLocalTime(data.info.createTime);
			    				str = "<tr><td>"+data._id+"</td><td>"+data.info.name+"</td><td>"+data.status.card+"</td><td>"+data.status.coin+"</td><td>"+time.toLocaleString()+"</td></tr>";
			    			}else{
			    				str = '没有该UID的信息';
			    			}
			    			$("#dataList").html(str);
			    		}
			    	});
			    });
			//	提交前
			        $('#pbtn').click(function () {
			            var user_id = $.trim($('#user_id').val());
			            var number = $.trim($('#number').val());
			            var limit = $(".limit").text();
			
						if(parseInt(number) > parseInt(limit)) {
							alert('剩余数量小于要充值的数量 ！');
							window.location.href = "{:U('Admin/Main/pay')}";
							return false;
						}
			            if (user_id == '') {
			            	alert("UID不能为空！");
			            	window.location.href = "{:U('Admin/Main/pay')}";
			                return false;
			            }
			
			            if (number == '' || Number(number) <= 0) {
			            	alert('输入的数字无效！');
			            	window.location.href = "{:U('Admin/Main/pay')}";
			                return false;
			            }
			
			            var params = {"user_id": user_id,"number": number,"uname":uname};
			            var url = "{:U('Admin/Main/paySave')}";
			            $.ajax({
			                type: "post",
			                url: url,
			                timeout: 5000, //超时时间设置，单位毫秒
			                dataType: "json",
			                data: params,
			                success: function (data) {
			                   if (data == 'success') {
			                        alert('充值成功!');
			                        window.location.href = "{:U('Admin/Main/pay')}";
			                    } else if (data == 'danger') {
			                    	alert("透支额度已超限！请立即充值");
			                    	window.location.href = "{:U('Admin/Main/buy')}";
			                    } else if (data == 'error') {
			                        alert('充值失败！');
			                        window.location.href="{:U('Admin/Main/pay')}";
			                    } else if (data == "invalid") {
			                    	alert("充值失败！你的账户已失效，请联系管理员");
			                    	window.location.href="{:U('Admin/Main/pay')}";
			                    } else if(data == 'cantpay') {
			                    	alert("抱歉！不能给自己充值！");
			                    	window.location.href="{:U('Admin/Main/pay')}";
			                    }else if(data == 'failure') {
			                    	alert("请求失败，充值未成功！");
			                    	window.location.href="{:U('Admin/Main/pay')}";
			                    }else if(data == 'longtime'){
			                    	alert("请求超时，充值未成功！");
			                    	window.location.href="{:U('Admin/Main/pay')}";
			                    }
			                },
			
			                complete: function (XMLHttpRequest, status) {
			                    if (status == "timeout") {
			                        alert("请求超时");
			                    }
			                }
			            });
			        })
			    });
			</script>
		</body>
	</html>


